
load('summary_data/figs7_8_A12_A13_A14.rda')
source('utils.R')

c1 = render_basic(c1) +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  scale_shape_manual(name = 'Gender',
                     values = c(20, 4),
                     labels = c('F', 'M')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Gender (Women, Men)'
  )

c9 = render_basic(c9) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  scale_shape_manual(
    name = 'Education',
    values = c(20, 4),
    labels = c('Non-Col. W', 'Col. W')
  ) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Education among Whites (Non-College, College)'
  )

c11 = render_basic(c11) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('NW', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (POC, White)'
  )

legend = c1 + guides(shape = 'none') + theme(legend.position = 'bottom')
legend = get_legend_35(legend)

c1 = c1 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  expand_limits(y = c(-1, 7)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Women', 'Men')
  ) +
  labs(subtitle = element_blank(), shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c9 = c9 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  expand_limits(y = c(-1, 7)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Non-College White', 'College White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c11 = c11 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 7, 1))) +
  expand_limits(y = c(-1, 7)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('POC', 'White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

plot = plot_grid(c1 + guides(shape = 'none'),
                 c9 + guides(shape = 'none'),
                 c11 + guides(shape = 'none'),
                 nrow = 1)

plot = plot_grid(plot, legend, rel_heights = c(9, .35), nrow = 2)

shapes = plot_grid(get_legend_35(c1),
                   get_legend_35(c9),
                   get_legend_35(c11),
                   nrow = 1)

plot = plot_grid(shapes, plot, rel_heights = c(.5, 9), nrow = 2)

ggsave(filename = 'figures/figA12.pdf', plot = plot, width = 8, height = 5, units = 'in')
